home *** CD-ROM | disk | FTP | other *** search
/ Eagles Nest BBS 8 / Eagles_Nest_Mac_Collection_Disc_8.TOAST / Developer Environments / MacCjr / MacC Jr / Serial Folder / serialTest.c
Encoding:
C/C++ Source or Header  |  1987-01-05  |  1.5 KB  |  48 lines  |  [TEXT/EDIT]

  1. // SerialTest.c
  2.  
  3. // ©Copyright 1987 Consulair Corp. All rights reserved
  4.  
  5. /*  This program does a simple serial loop test, reading characters from
  6.     the keyboard and sending them out port B (the printer port), and
  7.     receiving them from port A (the modem port).  In order to run it, you
  8.     need a cable which connects ports A and B through a "null modem", i.e.
  9.     the cable must have the send and receive lines swapped at one end.
  10.     Note that port A is opened for output even though it will only be used
  11.     for input.  This is because the serial driver is only initialized
  12.     when a port is opened for output.  Also notice the use of the feof
  13.     function on either the keyboard (stdin) or a serial port.  It returns
  14.     true if there are no characters buffered for the device, and false
  15.     if there are characters buffered.
  16.     */
  17.     
  18. #include <stdio.h>
  19.  
  20. main()
  21.   {
  22.   char c;
  23.   FILE *fileIn, *fileOut;
  24.   fileIn = fopen(".Aout", "W"); // open output to initialize the driver.
  25.   if ((fileIn = fopen(".Ain", "R")) == 0)
  26.     {
  27.     printf("\rCould Not Open Input");
  28.     getchar();
  29.     ExitToShell();
  30.     }
  31.   if (fileOut = fopen(".Bout", "W"))
  32.     {
  33.     printf("\rOutput and Input are Open. Type Any character\rClick Mouse Button to Quit.\r");
  34.     while (1)
  35.       {
  36.       if (!feof(stdin)) outch(fileOut, getchar());
  37.       if (!feof(fileIn)) putchar(getc(fileIn));
  38.       if (Button()) break;
  39.       }
  40.     }
  41.   else
  42.     {
  43.     printf("\rCould Not Open Output");
  44.     getchar();
  45.     ExitToShell();
  46.     }
  47.   }
  48.